# -*- coding:utf-8 -*-
import os
import time
import scrapy
from scrapy import Request
from scrapy import FormRequest
from dls.items import DlsItem

class SkillSpider(scrapy.Spider):
    name = "skill"
    page = 1;
    # allowed_domains = ["ikeepfit.cn"]
    start_urls = ["http://m.socialab.com.cn//m/"]

    def start_requests(self):
        for i in range(300,502):
            url = self.start_urls[0]
            time.sleep(1);
            self.page = i
            print i,"########"
            url = url+ ("%d" % (i))
            print url;
            yield Request(url)
    def parse(self,res):
        #print res.body
        title = res.xpath('//body/div/h3/text()').extract()
        img = res.xpath('//body/div/div/img/@src').extract()
        content = res.xpath('//body/div/div/p/text()').extract()
        try:
            item = DlsItem()
            item['title'] = title[0]
            item['content'] = content[0]
            item['img'] = img[0]
            item['image_urls'] = ["http://m.socialab.com.cn/"+img[0]]
            yield item
        except:
            return;

